Read lines from a file until the end of the file is reached.
The following example reads lines from a file until the end of the file is reached.
C# .NET |
public static String DoTest() { string strRet = ""; string path = @"c:\temp\MyTestReadLine.txt"; try { if (File.Exists(path)) { File.Delete(path); } StreamWriter sw = new StreamWriter(path); sw.WriteLine("This"); sw.WriteLine("is some text"); sw.WriteLine("to test"); sw.WriteLine("ReadLine method"); sw.Flush(); sw.Close(); StreamReader sr = new StreamReader(path); while (sr.Peek() >= 0) { strRet += (sr.ReadLine() + Environment.NewLine); } sr.Close(); } catch (Exception e) { strRet += String.Format("The process failed: {0}", e.ToString()); } return strRet; } |
Blaze++ .NET |
static String DoTest() { String strRet = ""; String path = "c:\\temp\\MyTestReadLine.txt"; try { if (File::Exists(path)) { File::Delete(path); } StreamWriter sw(path); sw.WriteLine("This"); sw.WriteLine("is some text"); sw.WriteLine("to test"); sw.WriteLine("ReadLine method"); sw.Close(); StreamReader sr(path); while (sr.Peek() >= 0) { strRet += (sr.ReadLine() + Environment::NewLine); } sr.Close(); } catch (Exception e) { strRet += String::Format("The process failed: {0}", e.ToString()); } return strRet; } |